<?php

require_once "config.php";

define('GESHI_BASEDIR',       'libs/geshi/');
define('TEMPLATE_DIR',        'templates/');
define('LANG_DIR',            'langs/');
define('CONFIG_VERSION',      1188844791);


session_start();

// MVC
require_once "libs/i18n.php";
require_once "libs/mvc.model.php";
require_once "libs/mvc.view.php";
require_once "libs/mvc.controller.php";

// GeSHi
require_once GESHI_BASEDIR . "geshi.php";

require_once "pastelog.controller.php";

$pastelog = new PasteLogController();

function arg($int)
{
    if (!isset($_GET['q'])) {
      return;
    }
    $args = explode('/', $_GET['q']);
    
    return $args[$int];
}

function url($uri) {
    static $base_url;
  
    if (empty($base_url)) {
        $url = parse_url('http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER["SCRIPT_NAME"]));
        $base_url = $url['scheme'].'://'.$url['host'];
        if ($url['path'] != '/') {
        $base_url .= $url['path'];
      }
    }

    if (CLEAN_URL)
        return $base_url.'/'.$uri;
    else
        return $base_url.'/?q='.$uri;
}

function my_smarty_url($params, &$smarty)
{
    return url($params['uri']);
}

$arg = arg(0);

if (isset($_POST['action']) && $_POST['action'] == 'savePaste') {
    $pastelog->savePaste();
} elseif (is_numeric($arg)) {
    $pastelog->displayPaste($arg);
} elseif ($arg == 'about') {
    $pastelog->displayAbout();
} elseif ($arg == 'captcha') {
    $pastelog->displayCaptcha();
} elseif ($arg == 'delete' && trim(arg(1)) != '') {
    $pastelog->deletePaste(arg(1));
} elseif ($arg == 'download' && is_numeric(arg(1))) {
    $pastelog->downloadPaste(arg(1));
} else {
    $pastelog->displayNew();
}

?>
